package com.axjy.controller;

import com.axjy.controller.vo.Node;
import com.axjy.pojo.Role;
import com.axjy.service.PermissionService;
import com.axjy.service.RoleService;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import javax.annotation.Resource;

/**
 * Created by asus on 2017/9/18.
 */
@RestController
@RequestMapping("/sys/role")
public class RoleHandler{

    Logger logger=Logger.getLogger(this.getClass());

    @Resource
    private RoleService roleService;

    @Resource
    private PermissionService permissionService;

    @RequestMapping("/list")
    public List<Role> list(){
        return roleService.list();
    }

    @RequestMapping("/tree")
    public List<Node> tree(Integer rid){
        return permissionService.search4Tree(rid);
    }

    @RequestMapping("/grant")
    public String grant(Integer rid,Integer[] mids){
        String msg="角色授权成功！";
        try{
            permissionService.grant4Role(rid,mids);
        }catch(Exception ex){
            msg="角色授权失败！";
            logger.error(msg,ex);
        }

        return msg;
    }


}
